package com.car.rental.order.service.impl;

import com.car.rental.order.config.RabbitMQConfig;
import com.car.rental.order.service.MessageService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;

@Slf4j
@Service
@RequiredArgsConstructor
public class MessageServiceImpl implements MessageService {

    private final RabbitTemplate rabbitTemplate;

    @Override
    public void sendOrderStatusMessage(String orderNo) {
        log.info("发送订单状态变更消息，订单号：{}", orderNo);
        rabbitTemplate.convertAndSend(
            RabbitMQConfig.ORDER_STATUS_EXCHANGE,
            RabbitMQConfig.ORDER_STATUS_ROUTING_KEY,
            orderNo
        );
    }

    @Override
    public void sendPaymentStatusMessage(String paymentNo, Long vehicleId, Integer status) {
        log.info("发送支付状态变更消息，支付流水号：{}，车辆ID：{}", paymentNo, vehicleId);
        
        Map<String, Object> message = new HashMap<>();
        message.put("paymentNo", paymentNo);
        message.put("vehicleId", vehicleId);
        message.put("status", status);
        
        rabbitTemplate.convertAndSend("payment.status.exchange", "payment.status", message);
    }

    @Override
    public void sendRentalReminderMessage(String orderNo) {
        log.info("发送租期提醒消息，订单号：{}", orderNo);
        rabbitTemplate.convertAndSend(
            RabbitMQConfig.RENTAL_REMINDER_EXCHANGE,
            RabbitMQConfig.RENTAL_REMINDER_ROUTING_KEY,
            orderNo
        );
    }
} 